﻿package mortal.game.view.market.sale
{
    import Message.Public.*;
    import com.gengine.utils.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.market.*;
    import mortal.game.view.market.alert.*;
    import mortal.mvc.core.*;

    public class MktSaleGlod extends MktSaleBase
    {
        protected var _txtCount:MoneyInput;

        public function MktSaleGlod()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._txtCount.dispose(param1);
            this._txtCount = null;
            return;
        }// end function

        override protected function resetUI() : void
        {
            super.resetUI();
            this._txtCount = UIFactory.getUICompoment(MoneyInput, 115, 144, this);
            _title.visible = false;
            this._txtCount.minValue = 1;
            this._txtCount.value = this._txtCount.minValue;
            this._txtCount.maxValue = 999;
            this._txtCount.unit = EPriceUnit._EPriceUnitGold;
            _txtPrice.unit = EPriceUnit._EPriceUnitCoin;
            updateUnit();
            _item.source = GlobalClass.getBitmapData(ImagesConst.zuanshi);
            this.reset(true);
            return;
        }// end function

        override protected function clickHandler(event:MouseEvent) : void
        {
            if (event.currentTarget == _btnReset)
            {
                this.reset();
            }
            else if (event.currentTarget == _btnSale)
            {
                this.sale();
            }
            return;
        }// end function

        override protected function reset(param1:Boolean = false) : void
        {
            super.reset(param1);
            this._txtCount.value = this._txtCount.minValue;
            this._txtPrice.textInput.text = "";
            return;
        }// end function

        private function sale() : void
        {
            if (this._txtPrice.value <= 0)
            {
                MsgManager.showRollTipsMsg("请输入正确的价格");
                return;
            }
            if (!Cache.instance.role.enoughMoney(EPriceUnit._EPriceUnitGold, this._txtCount.value))
            {
                MsgManager.showRollTipsMsg("钻石不足");
                return;
            }
            var _loc_1:* = this._btnBroadcast.selected ? (MktModConfig.BroadcastCost) : (0);
            _loc_1 = _loc_1 + _txtTax.value;
            if (!Cache.instance.role.enoughMoney(EPriceUnit._EPriceUnitCoinBind, _loc_1))
            {
                MsgManager.showRollTipsMsg("金币不足");
                return;
            }
            var _loc_2:* = "你将以" + HTMLUtil.addColor(this._txtPrice.value.toString(), GlobalStyle.colorHuang) + GameDefConfig.instance.getEPrictNameAddColoer(this._txtPrice.unit, GlobalStyle.colorHuang) + "的价格寄售" + HTMLUtil.addColor(this._txtCount.value.toString(), GlobalStyle.colorHuang) + GameDefConfig.instance.getEPrictNameAddColoer(this._txtCount.unit, GlobalStyle.colorHuang) + "，寄售时间" + HTMLUtil.addColor(this._timeBox.selectedItem.timeType, GlobalStyle.colorHuang) + HTMLUtil.addColor("小时", GlobalStyle.colorHuang);
            var _loc_3:String = "";
            if (this._txtPrice.unit == EPriceUnit._EPriceUnitCoin)
            {
                _loc_3 = TodayNoTipsConst.MarketSaleByCoin;
            }
            else if (this._txtPrice.unit == EPriceUnit._EPriceUnitGold)
            {
                _loc_3 = TodayNoTipsConst.MarketSaleByGold;
            }
            var _loc_4:Object = {};
            _loc_4.unit = this._txtPrice.unit;
            _loc_4.str = "寄售";
            Alert.extendObj = _loc_4;
            TodayNotTipUtil.toDayNotTip(_loc_3, this.onSelect, _loc_2, null, Alert.OK | Alert.CANCEL, null, null, null, 4, MktTodayNoTipAlert);
            return;
        }// end function

        private function onSelect() : void
        {
            var _loc_1:Object = {};
            _loc_1.code = EPriceUnit._EPriceUnitGold;
            _loc_1.itemUid = "";
            _loc_1.amount = this._txtCount.value;
            _loc_1.price = this._txtPrice.value;
            _loc_1.unit = this._txtPrice.unit;
            _loc_1.time = this._timeBox.selectedItem.timeType;
            _loc_1.broadcast = this._btnBroadcast.selected;
            Dispatcher.dispatchEvent(new DataEvent(EventName.MarketSale, _loc_1));
            return;
        }// end function

    }
}
